package com.dcits.electronic_account.mapper;

import com.dcits.electronic_account.bean.Flow;
import com.dcits.electronic_account.bean.VirtualAccount;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

/**
 * @author: YHC
 * @Date: 2022/6/25
 */
@Mapper
public interface TransferAccountsMapper {

    //根据户名查询账户
    @Select("select user_id,user_name,login_pwd,pay_pwd,id_number,phone,name,balance from electronic_account.virtual_account where user_name=#{userName}")
    VirtualAccount searchVirByUserName(String userName);

    //根据手机号查询账户
    @Select("select user_id,user_name,login_pwd,pay_pwd,id_number,phone,name,balance from electronic_account.virtual_account where phone=#{virPhone}")
    VirtualAccount searchVirByPhone(String virPhone);

    //根据用户手机号更新账户余额
    @Update("update electronic_account.virtual_account set balance=#{balance} where phone=#{virPhone}")
    int updateBalance(@Param("balance") BigDecimal balance,@Param("virPhone") String virPhone);

    //添加流水
    @Insert("insert into electronic_account.flow(time,type,amount,payer,payee) values(#{time},#{type},#{amount},#{payer},#{payee})")
    int addFlow(Flow flow);

}
